/*
 * 2.5_1.cpp
 *
 *  Created on: 2012-5-17
 *      Author: jawinton
 */


#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main (void) {
	int t[6], rest[2]={0}, total;
	int u[4] = {0, 5, 3, 1};
	while (true) {
		cin >> t[0] >> t[1] >> t[2] >> t[3] >> t[4] >> t[5];
		if (t[1] == 0 && t[2] == 0 && t[3] == 0 &&
			t[4] == 0 && t[5] == 0 && t[0] == 0) return 0;

		total = t[5] + t[4] + t[3] + (t[2]+3)/4;
		rest[1] = 5*t[3] + u[t[2]%4];
		if(rest[1] < t[1]) total += (t[1]-rest[1]+8)/9;
		rest[0] = 36*total - 36*t[5] - 25*t[4] - 16*t[3] - 9*t[2] - 4*t[1];
		if(rest[0] < t[0]) total += (t[0]-rest[0]+35)/36;
		cout << total << endl;
	}
	return 0;
}
